package com.xxzb.pack0824.线程池;


import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * 使用单一线程池
 * 由结果可见一直使用的都是一个线程池
 */
public class SingleThreadPoolDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //创建一个单一线程池对象
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        //创建线程任务
        ThreadPoolTask task = new ThreadPoolTask();
        //向线程池中提交线程任务
        Future<Integer> future = executorService.submit(task);
        System.out.println(future.get());
        ThreadPoolTask task1 = new ThreadPoolTask();
        executorService.submit(task1);
        //关闭线程池
        executorService.shutdown();

    }
}
